package ms.utils;

import ms.jasim.framework.IConfiguration;
import ms.jasim.framework.JasimFramework;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.impl.EClassImpl;

public class MyEClassImpl extends EClassImpl {
	
	private IConfiguration config;
	private EAttribute nameAttribute;
	private boolean isInitialized;

	@Override
	public EAttribute getEIDAttribute() {
		EAttribute result = super.getEIDAttribute();
		if (config == null)
			this.config = JasimFramework.getConfiguration();
		if (config != null && config.getBoolean(IConfiguration.USE_NAME_AS_ID, false)) {
			if (nameAttribute == null && !this.isInitialized) {
				this.isInitialized = true;
				for (EAttribute att: getEAllAttributes())
					if ("name".equalsIgnoreCase(att.getName())) {
						this.nameAttribute = att;
						att.setID(true);
						break;
					}
			}
			if (nameAttribute != null) 
				result = nameAttribute;
		}
		return result;
	}
}
